function f_get_html_info_for_pro()
{
    declare _port _order_id script_start_time __id __ line1 order_id res_file
    _port="${1}"
    _order_id="${2}"
    res_file="${work_dir}/logs/.res${_port}.log"
    __="select concat(start_time,':::',remarks,':::',id,':::',table_name,':::',user_mail,':::',order_id) from ${t_prog_task} 
        where port = ${_port} and order_id = ${_order_id} and send_state = 0 order by id desc limit 1;"
    __="$(timeout ${exe_time} ${mysql_comm_dbadb} -NBe "${__}" 2>/dev/null)" && exe_state="${?}" || exe_state="${?}"
    script_start_time="$(awk -F::: '{print $1}' <<< "${__}")"
    __id="$(awk -F::: '{print $3}' <<< "${__}")"
    table_name="$(awk -F::: '{print $4}' <<< "${__}")"
    user_mail_name="$(awk -F::: '{print $5}' <<< "${__}")"
    order_id="$(awk -F::: '{print $6}' <<< "${__}")"
    [ "${order_id}x" != "${__id}x" -a "${order_id}x" != "0x" ] && order_id="(工单:${order_id})" || order_id=""
    _update="update ${t_prog_task} set send_state = 2 where send_state = 0 and port = ${_port} and table_name = '${table_name}' and id <= ${__id};"
    _update_delete="update ${t_prog_task} set send_state = 1 where send_state = 0 and port = ${_port} and table_name = '${table_name}' and id <= ${__id};"
    _delete="delete from ${t_prog_task} where send_state = 1 and port = ${_port} and table_name = '${table_name}' and id <= ${__id};"
    awk -F:::  '{print $2}' <<< "${__}" |tr ";" "\n"|sed '/^$/d' > ${res_file}
    [ ! -s "${res_file}" ] && rm -f ${res_file} && return 0
    echo " 
<html>
    <head>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
        <title>${_port}-改表进度信息监控</title>
    </head>
    <body>
        <p>采集时间: $(date "+%F %H:%M:%S")</p>
        <table  border='1' cellspacing='0'>
            <td colspan="3">${_port}端口${order_id}改表监控, 正在进行的表：${table_name}</td>
            <tr>
                <th width=200>开始时间</th> 
                <th width=200>完成百分比</th>
                <th width=200>预计剩余时间</th>
            </tr>
            $(
                line1=$(head -1 ${res_file})
                echo "
            <tr>
                <th rowspan='10'>${script_start_time}</th>
                <th>$(awk '{print $1}' <<< "${line1}")</th>
                <th>$(awk '{print $2}' <<< "${line1}"|sed 's#N/A#计算中#g;s#due#即将完成, 请耐心等待#g')</th>
            </tr>
                "
                sed -n '2,$p' ${res_file}|while read line
                do
                    echo "
            <tr>
                <th>$(awk '{print $1}' <<< "${line}")</th>
                <th>$(awk '{print $2}' <<< "${line}"|sed 's#N/A#计算中#g;s#due#即将完成, 请耐心等待#g')</th>
            </tr>
                    "
                done
            )
        </table>
        <p><span style='color:red;'><strong> 提示：一个工单存多个改表sql将按照顺序执行. 该表(${table_name})之前的均已经改完, 该表之后的还未开始.</strong></span></p>
    </body>
</html>
   "
   [ -f "${res_file}" ] && rm -f ${res_file}
}

function f_get_html_info_prepare_for_pro()
{
    declare port order_id title_info _html_file exe_state
    port="${1}"
    order_id="${2}"
    _html_file="${html_file}.pro"
    f_get_html_info_for_pro "${port}" "${order_id}" > ${_html_file}
    sed -i '/^$/d' ${_html_file} || true
    if [ ! -s "${_html_file}" ]
    then
        [ -f "${_html_file}" ] && rm -f "${_html_file}"
        return 0
    fi
    title_info="【巡检】${port}-改表进度监控"
    ${send_mail_script} -s "${title_info}" -u ${g_user_mail_addr} -f ${_html_file} -t html && exe_state="${?}" || exe_state="${?}"
    if [ ${exe_state} -ne 0 ]
    then
        timeout ${exe_time} ${mysql_comm_dbadb} -NBe "${_update}" 2>/dev/null || true
    else #发送成功就删除
        timeout ${exe_time} ${mysql_comm_dbadb} -NBe "${_delete}${_update_delete}" 2>/dev/null || true
    fi
    unset _update _delete _update_delete
    [ -f "${_html_file}" ] && rm -f "${_html_file}"
    return 0
}

